import net from '@/util/net'
import server from '@/config/servers'

export default ({
  state: {
    update_time: null,
    dept_info: []
  },
  getters: {},
  mutations: {
    saveUpdateTime(state) {
      state.update_time = +new Date()
    },
    /**
     * 更新组织名称信息
     * @param {*} state
     * @param {*} value
     */
    DepartmentInfo(state, value) {
      state.dept_info = value
      console.log(state.dept_info)
    }
  },
  actions: {
    /**
     * 更新组织名称信息
     */
    updateDepartmentNameInfo({ state, commit, getters, rootState }) {
      rootState.launch.then(() => {
        net.send({
          server: server.CallAcc.get_department_tree,
          data: {
            deptCode: rootState.user.departments[0].deptCode
          }
        }).then((data) => {
          commit('DepartmentInfo', data)
        }, ex => console.log(ex))
      })
    }
  }
})
